#!/bin/bash

#Build an xorg/mesa/drm/linux graphic stack from bare source code.
#Target hw is radeonsi, namely at least radeon hd78xxx.
#Dependencies not installed here:
# - build tools (C and C++(!!!!!!!)...)
#   **the xcb totally brain fucked build system must have python2 and not 3**
# - llvm ugly thingy

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig
export ACLOCAL_PATH=/usr/local/share/aclocal

function autogen_cleanup () {
  echo INFO:cleaning ${1} autogen.sh
  cd ${1}
  sed '/srcdir\/configure/ c\echo no configure call' -i autogen.sh
  sed '/"$srcdir"\/configure/ c\echo no configure call' -i autogen.sh
  sed '/\.\/configure/ d' -i autogen.sh
  sed '/"${srcdir}"\/configure/ d' -i autogen.sh
  ./autogen.sh
  cd ../
}

function pkg_type1 () {
  local pkg_name=${1}
  autogen_cleanup ${pkg_name}
  
  local build_dir=build/${pkg_name}
  rm -Rf ${build_dir}
  mkdir -p ${build_dir}
  cd ${build_dir}
  echo INFO:configuring ${pkg_name}
  ../../${pkg_name}/configure --with-gnu-ld ${2}
  make
  make install
  cd ../..
}

#must build in its source dir
function pkg_type2 () {
  local pkg_name=${1}
  autogen_cleanup ${pkg_name}

  cd ${pkg_name}  
  echo INFO:configuring ${pkg_name}
  ./configure --with-gnu-ld ${2}
  make
  make install
  cd ..
}

#********************************************************************************
#start:uncommon build system tools


#================================================================================
#**the *3* following package must be installed to be able to run autogen.sh
#for the other source packages

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/util/macros
##0890e4003aacfa7113ab3f4e3ad7c5636f8e922a
#pkg_type1 macros
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://git.iplinux.org/xtrans.git
##e866b42d01b7b562c3a274833b179e70f7c9a940
#pkg_type1 xtrans
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##font-util
##git://anongit.freedesktop.org/xorg/font/util
##dff77bb76ab2260877a37193df1d728d2f4a1d88
#pkg_type1 util
##-------------------------------------------------------------------------------
#================================================================================


##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/util/makedepend
##49d72ba286c1ddd99cf1e6477ee2b6af59007341
#pkg_type1 makedepend
##-------------------------------------------------------------------------------

#end:uncommon build system tools
#********************************************************************************




#********************************************************************************
#start:headers of X protocols

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/xproto
##c76d51423d6a6afe4f0c8fc6f863ba97d202184b
#pkg_type1 xproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/xextproto
##dff1a34f49644b2ed9cfac321dce6d31aed868cf
#pkg_type1 xextproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/kbproto
##391a1f6de6315fc0196d407d800597488315cccb
#pkg_type1 kbproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/inputproto
##3ed8aed32199edaa8621ccea571a04883e050cb5
#pkg_type1 inputproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/glproto
##ec1eec4355ee4a6c5134f2178192f10b6d28a87a
#pkg_type1 glproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/dri2proto
##4eeacce4c4a300b938b7e3fb78a8e443c491780b
#pkg_type1 dri2proto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/damageproto
##f9a0f468c49f65c7a415aafc812dd1d0321920e8
#pkg_type1 damageproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/fixesproto
##b8a682cc30499a751091c84efabb3012e02f47c5
#pkg_type1 fixesproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/xcmiscproto
##f18667046964759f1fe086ade26829f6ced4fea7
#pkg_type1 xcmiscproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/bigreqsproto
##9880dfa3489eddd8aaa1bdf24f621b13e514d5db
#pkg_type1 bigreqsproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/randrproto
##b52f4e39b670e98e56e346b7aa1393a2b24544f2
#pkg_type1 randrproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/renderproto
##eebdef62c9a6f27f5fe2e71ce5873d5397d34d04
#pkg_type1 renderproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/fontsproto
##607784e2ad522b7dff32da82480acf6934dc4a23
#pkg_type1 fontsproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/videoproto
##b994209d8559a0d0802487ed53585404b398a707
#pkg_type1 videoproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/compositeproto
##d358d6290af3d9cedb7b6d7e16058370e4779508
#pkg_type1 compositeproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/recordproto
##32236c56b7015a98d845bb1836817328a307edce
#pkg_type1 recordproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/scrnsaverproto
##c33f4368e85d976b112dda4a34ca254944cb354d
#pkg_type1 scrnsaverproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/resourceproto
##4be619918d604cbf63994ebe8357b811b5bd2452
#pkg_type1 resourceproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/xf86driproto
##3040728fda7c54eb0c606adef43f766483c57d85
#pkg_type1 xf86driproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/proto/xineramaproto
##f35bbf01ca1629c64a526904b1633f58e8ac40a2
#pkg_type1 xineramaproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##missed by the xorg server autoconf detection
##git://anongit.freedesktop.org/xorg/proto/xf86vidmodeproto
##4ffa46d9d10267f0156b803a941de05e1c0e47a6
#pkg_type1 xf86vidmodeproto
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##this is xcb protocol description
##git://anongit.freedesktop.org/xcb/proto
##d42d791806f8917f32e869f01e0895400bfb2688
#pkg_type1 proto
##-------------------------------------------------------------------------------

#end:headers of X protocols
#********************************************************************************




##-------------------------------------------------------------------------------
##git://git.sv.nongnu.org/freetype/freetype2.git
##
#pkg_type1 freetype2
##-------------------------------------------------------------------------------




#********************************************************************************
#start:X11 libs

##-------------------------------------------------------------------------------
##git://git.iplinux.org/libxau.git
##b8173c2017052e1e047ffae8f3ba07aeb1f7f0a0
#pkg_type1 libxau
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xcb/libxcb
##23911a707b8845bff52cd7853fc5d59fb0823cef
#pkg_type1 libxcb
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libX11
##d45b3fc19fbe95c41afc4e51d768df6d42332010
#pkg_type1 libX11
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXext
##7081afc98643e3ef8a3ed711183c8fc8fef30cfa
#pkg_type1 libXext
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXfixes
##ca7b0066fe6f315d2499338cd133e5b1e9d11236
#pkg_type1 libXfixes
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXdamage
##665c80d7af5fc7a73b76e0ddaee3536b37b029e9
#pkg_type1 libXdamage
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libxkbfile
##5e3da29093ff5d5b6b8805467a523d5cb7663965
#pkg_type1 libxkbfile
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libfontenc
##7de846ed190b2564b0642de79918dd3804083b4e
#pkg_type1 libfontenc
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXfont
##3c534f72d6d4327926474a5f8fa53cbcf19de3cf
#pkg_type1 libXfont
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libpciaccess
##09f5b48f559888339450bb4a79d178c94da34638
#pkg_type1 libpciaccess
##-------------------------------------------------------------------------------

#end:X11 libs
#********************************************************************************




##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/mesa/mesa
##36ea744f58e5b436c45ed857bd92bbb472e641d5
#pkg_type2 mesa "\
#  --enable-debug \
#  --enable-texture-float \
#  --enable-gles \
#  --enable-glx-tls \
#  --enable-gallium-egl \
#  --enable-gallium-gbm \
#  --enable-gbm \
#  --enable-gallium-tests \
#  --enable-r600-llvm-compiler \
#  --with-egl-platforms=x11,drm \
#  --with-dri-drivers=radeon,swrast \
#  --with-gallium-drivers=radeonsi,swrast"
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/pixman
##d4b72eb6ccc1f004efedbc6552ee22499350be4d
#pkg_type1 pixman
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/xserver
##0b02150c27e98f996e10d7489f9f67a30e4e3497
#pkg_type1 xserver "\
#  --enable-glx-tls \
#  --disable-vgahw \
#  --disable-vbe \
#  --disable-dmx \
#  --disable-xvfb \
#  --disable-xnest \
#  --disable-xquartz \
#  --disable-xwin \
#  --disable-xephyr \
#  --disable-xfake \
#  --disable-xfbdev \
#  --disable-kdrive-kbd \
#  --disable-kdrive-mouse \
#  --disable-kdrive-evdev"
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/driver/xf86-input-evdev
##5af11b675242b2971f47c42a57b892dc24eb1917
#pkg_type1 xf86-input-evdev
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/driver/glamor
##9b8a791290af0add84269efdb315f9f58798f6d2
#pkg_type1 glamor "--enable-debug --enable-glx-tls"
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/driver/xf86-video-ati
##e8cb0b721e6ea251f85c799ca0563bfa59a2d37c
#pkg_type1 xf86-video-ati --enable-glamor
##-------------------------------------------------------------------------------




#********************************************************************************
#start:runtime dependencies

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/app/xkbcomp
##f2eff337176551f643e35c54c1e1ca0a78df69c6
#pkg_type1 xkbcomp
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xkeyboard-config
##159e8db2a3829a11801d06cc6cad6d1378551dd5
#pkg_type1 xkeyboard-config
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##cannot be configured more than once
##git://people.freedesktop.org/~mareko/libtxc_dxtn
##a875bdef81facae08267c002590ad5b7f90e1eaf
#pkg_type1 libtxc_dxtn 
##------------------------------------------------------------------------------

#end:runtime dependencies
#*******************************************************************************




#*******************************************************************************
#start:basic X applications

#===============================================================================
#additional X libs dependencies

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/fontconfig
##8daa863c6d84ea56cc2f568a89316690e784a277
#pkg_type1 fontconfig
##-------------------------------------------------------------------------------

#===============================================================================

#===============================================================================
#additional X libs

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libSM
##b3d1f4896cab54717acd691b62b7fa3122a5fd8c
#pkg_type1 libSM
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libICE
##f166e8bbf16ec214fefdcf02ce81f80442899cb7
#pkg_type1 libICE 
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXt
##690d6587e7e0ba29b70d2b1d6c5c6a128c5547a2
#pkg_type1 libXt
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXmu
##6437d834cd66621e4e9f4decf7341b6d7ff45556
#pkg_type1 libXmu
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXau
##f2b24dd74614ce807cacf764c6eddd834feffc5a
#pkg_type1 libXau
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXpm
##acaaea96776b36c097d5413040c5ce85d3ae6cb9
#pkg_type1 libXpm
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXaw
##ffaad7ee2ef6e06b4585567df04f6b64356fb6fe
#pkg_type1 libXaw
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXrender
##bf1aa4e05997ab97be4413ccdb6d0d1eb45aeefe
#pkg_type1 libXrender
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXft
##0847b64af14acefaa7aa86b3cec8632497babe73
#pkg_type1 libXft
##-------------------------------------------------------------------------------

#===============================================================================

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/app/xclock
##69de4eaa3be6cc177eb53a4754cb6bd35340c585
#pkg_type1 xclock
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/app/oclock
##0563142cc89b04d1bca3208751b186df9649dbda
#pkg_type1 oclock
##-------------------------------------------------------------------------------

#end:basic X applications
#********************************************************************************




#*******************************************************************************
#start:3D applications

#===============================================================================
#additional dependencies: additionnal X libs and misc

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/xorg/lib/libXi
##ae163b6202d844a46541928d00049b29cbdf930f
#pkg_type1 libXi
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://glew.git.sourceforge.net/gitroot/glew/glew
##287c58f930f164f49cad8414846d511a15c91e50
#cd glew
#export GLEW_DEST=/usr/local
#export SYSTEM=linux
#make extensions
#make all
#make install.all
#cd ..
#exit
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/mesa/glu
##030651b64854b84a01ebebad9af188e7644c541a
#pkg_type1 glu
##-------------------------------------------------------------------------------

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/mesa/glut
##bca07f1fc0ba22055414cf78849e078d4978f347
#pkg_type2 glut --enable-texture-float
##-------------------------------------------------------------------------------

#===============================================================================

##-------------------------------------------------------------------------------
##git://anongit.freedesktop.org/mesa/demos
##73bc55b2accaa325b38e20ce1eec6c66bd4ecbb9
#pkg_type1 demos
##-------------------------------------------------------------------------------

#end:3D applications
#*******************************************************************************
